package admin.forms;

import java.util.TreeMap;

import javax.servlet.http.HttpServletRequest;

import entities.Category;


public class CategoryForm {
	public static TreeMap checkValid(HttpServletRequest request, Category category) {
		TreeMap form = new TreeMap();
		TreeMap check = new TreeMap();
		
		String id = (String) request.getParameter("id");
		String name = (String) request.getParameter("name");
		String alias = (String) request.getParameter("alias");
		
		category.setId(id);
		
		if (name == null || name.isEmpty()) {
			check.put("name", "Name is not null.");
			category.setName("");
		} else {
			category.setName(name);
		}
		
		if (alias != null) {
			category.setAlias(alias);
		}
		
		form.put("checkValid", check);
		form.put("category", category);
		
		return form;
	}
}
